package com.llc.spring.cloud.sdk.core.http;

import com.alibaba.fastjson.JSON;

/**
 * time 2018/8/27 17:45
 *
 * @author xiaojie.zhu <br>
 */
public class ResultUtil {

    public static <T> T parse(String content , Class<T> t){
        if(content == null){
            return null;
        }else{
            if(t == int.class || t == Integer.class){
                return (T) Integer.valueOf(Integer.parseInt(content));

            }else if(t == long.class || t == Long.class){
                return (T) Long.valueOf(Long.parseLong(content));

            }else if(double.class == t || Double.class == t){
                return (T) Double.valueOf(Double.parseDouble(content));

            }else if(short.class == t || Short.class == t){
                return (T) Short.valueOf(content);

            }else if(float.class == t || Float.class == t){
                return (T) Float.valueOf(content);
            }else{
                T t1 = JSON.parseObject(content, t);
                return t1;
            }
        }
    }
}
